/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * verDatos.java
 *
 * Created on 20-abr-2011, 2:21:44
 */

package interfaces;

import GestorClinico.Direccion;
import GestorUsuarios.GeneroUsuario;
import GestorUsuarios.Usuario;
import clinica.ClinicaView;
import clinica.Interfaces;
import clinica.Interfaz;
import java.awt.CardLayout;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Victor
 */
public class verDatos extends javax.swing.JPanel {

    private ClinicaView app;

    private Interfaces anterior;

    /** Creates new form verDatos */
    public verDatos(ClinicaView a) {
        initComponents();
        app = a;
        tabla.setRowHeight(38);
    }

    public void refresh() {
        aceptar.setFont(Interfaz.setFontSizeDinamic());
        apellidos.setFont(Interfaz.setFontSizeDinamic());
        correo.setFont(Interfaz.setFontSizeDinamic());
        dni.setFont(Interfaz.setFontSizeDinamic());
        fecha.setFont(Interfaz.setFontSizeDinamic());
        jLabel1.setFont(Interfaz.setFontSizeDinamic());
        jLabel2.setFont(Interfaz.setFontSizeDinamic());
        jLabel3.setFont(Interfaz.setFontSizeDinamic());
        jLabel4.setFont(Interfaz.setFontSizeDinamic());
        jLabel5.setFont(Interfaz.setFontSizeDinamic());
        jLabel6.setFont(Interfaz.setFontSizeDinamic());
        jLabel7.setFont(Interfaz.setFontSizeDinamic());
        jLabel8.setFont(Interfaz.setFontSizeDinamic());
        login.setFont(Interfaz.setFontSizeDinamic());
        nombre.setFont(Interfaz.setFontSizeDinamic());
        sexo.setFont(Interfaz.setFontSizeDinamic());
        telefono.setFont(Interfaz.setFontSizeDinamic());
        jPanel1.setBorder(Interfaz.setFontSizeBorder(jPanel1));
        jPanel4.setBorder(Interfaz.setFontSizeBorder(jPanel4));
    }

    public void rellenaDatos(Usuario u, Interfaces ant) throws SQLException, IOException, ClassNotFoundException {
        anterior = ant;
        nombre.setText(u.getNombre());
        apellidos.setText(u.getApellidos());
        dni.setText(u.getDniPasaporte());
        fecha.setText(u.getFechaNacimiento().toString());
        correo.setText(u.getCorreo());
        telefono.setText(""+u.getTelefonoMovil());
        if(u.getGenero()==GeneroUsuario.MASCULINO)
            sexo.setText("Hombre");
        else sexo.setText("Mujer");
        login.setText(u.getLogin());

        while( ((DefaultTableModel)tabla.getModel()).getRowCount() > 0 )
            ((DefaultTableModel)tabla.getModel()).removeRow(0);

        Direccion [] direcciones = u.getDirecciones();
        if(direcciones!=null)
        for(Direccion d:direcciones) {
            String [] valores = {d.getDireccion(),d.getLocalidad(),""+d.getCP(),d.getPais(),""+d.getTelefono()};
            ((DefaultTableModel)tabla.getModel()).addRow(valores);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        nombre = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        apellidos = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        dni = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        correo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        telefono = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        fecha = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        sexo = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        login = new javax.swing.JTextField();
        aceptar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabla = new javax.swing.JTable();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(verDatos.class);
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel4.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, Interfaz.setFontSize())); // NOI18N
        jPanel4.setName("jPanel4"); // NOI18N
        jPanel4.setLayout(new java.awt.GridLayout(4, 4));

        jLabel2.setFont(Interfaz.setFontSize());
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N
        jPanel4.add(jLabel2);

        nombre.setEditable(false);
        nombre.setFont(Interfaz.setFontSize());
        nombre.setText(resourceMap.getString("nombre.text")); // NOI18N
        nombre.setName("nombre"); // NOI18N
        jPanel4.add(nombre);

        jLabel3.setFont(Interfaz.setFontSize());
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N
        jPanel4.add(jLabel3);

        apellidos.setEditable(false);
        apellidos.setFont(Interfaz.setFontSize());
        apellidos.setText(resourceMap.getString("apellidos.text")); // NOI18N
        apellidos.setName("apellidos"); // NOI18N
        jPanel4.add(apellidos);

        jLabel4.setFont(Interfaz.setFontSize());
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N
        jPanel4.add(jLabel4);

        dni.setEditable(false);
        dni.setFont(Interfaz.setFontSize());
        dni.setText(resourceMap.getString("dni.text")); // NOI18N
        dni.setName("dni"); // NOI18N
        jPanel4.add(dni);

        jLabel5.setFont(Interfaz.setFontSize());
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N
        jPanel4.add(jLabel5);

        correo.setEditable(false);
        correo.setFont(Interfaz.setFontSize());
        correo.setText(resourceMap.getString("correo.text")); // NOI18N
        correo.setName("correo"); // NOI18N
        jPanel4.add(correo);

        jLabel6.setFont(Interfaz.setFontSize());
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N
        jPanel4.add(jLabel6);

        telefono.setEditable(false);
        telefono.setFont(Interfaz.setFontSize());
        telefono.setText(resourceMap.getString("telefono.text")); // NOI18N
        telefono.setName("telefono"); // NOI18N
        jPanel4.add(telefono);

        jLabel7.setFont(Interfaz.setFontSize());
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N
        jPanel4.add(jLabel7);

        fecha.setEditable(false);
        fecha.setFont(Interfaz.setFontSize());
        fecha.setText(resourceMap.getString("fecha.text")); // NOI18N
        fecha.setName("fecha"); // NOI18N
        jPanel4.add(fecha);

        jLabel8.setFont(Interfaz.setFontSize());
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N
        jPanel4.add(jLabel8);

        sexo.setEditable(false);
        sexo.setFont(Interfaz.setFontSize());
        sexo.setText(resourceMap.getString("sexo.text")); // NOI18N
        sexo.setName("sexo"); // NOI18N
        jPanel4.add(sexo);

        jLabel1.setFont(Interfaz.setFontSize());
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jPanel4.add(jLabel1);

        login.setEditable(false);
        login.setFont(Interfaz.setFontSize());
        login.setText(resourceMap.getString("login.text")); // NOI18N
        login.setName("login"); // NOI18N
        jPanel4.add(login);

        aceptar.setFont(resourceMap.getFont("aceptar.font")); // NOI18N
        aceptar.setIcon(resourceMap.getIcon("aceptar.icon")); // NOI18N
        aceptar.setText(resourceMap.getString("aceptar.text")); // NOI18N
        aceptar.setName("aceptar"); // NOI18N
        aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jPanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, Interfaz.setFontSize())); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tabla.setFont(Interfaz.setFontSize());
        tabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Direccion", "Localidad", "Cod.Postal", "Pais", "Telefono"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabla.setName("tabla"); // NOI18N
        jScrollPane1.setViewportView(tabla);
        tabla.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("tabla.columnModel.title0")); // NOI18N
        tabla.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("tabla.columnModel.title1")); // NOI18N
        tabla.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("tabla.columnModel.title2")); // NOI18N
        tabla.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("tabla.columnModel.title3")); // NOI18N
        tabla.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("tabla.columnModel.title4")); // NOI18N
        tabla.getTableHeader().setFont(resourceMap.getFont("tabla.font"));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 837, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 873, Short.MAX_VALUE)
                    .addComponent(aceptar, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(aceptar)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void aceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarActionPerformed

            app.volver(anterior);
    }//GEN-LAST:event_aceptarActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton aceptar;
    private javax.swing.JTextField apellidos;
    private javax.swing.JTextField correo;
    private javax.swing.JTextField dni;
    private javax.swing.JTextField fecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField login;
    private javax.swing.JTextField nombre;
    private javax.swing.JTextField sexo;
    private javax.swing.JTable tabla;
    private javax.swing.JTextField telefono;
    // End of variables declaration//GEN-END:variables

}
